<div class="col-sm-12">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>修改广告位</h5>

        </div>
        <div class="ibox-content">
            <form method="post" id="form" action="update?id={$model.id}" class="form-horizontal" enctype="multipart/form-data">

                <div class="form-group">
                    <label class="col-sm-3 control-label">广告位名称：</label>
                    <div class="col-sm-9">
                        <input required type="text" value="{$model.title}" name="title" class="form-control" placeholder="" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">尺寸(px)：</label>
                    <div class="col-sm-3">
                        <input required type="text" name="width" value="{$model.width}" class="form-control" placeholder="宽度" />
                    </div>
                    <div class="col-sm-3">
                        <input required type="text" name="height" value="{$model.height}" class="form-control" placeholder="高度" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">单价(元/月)：</label>
                    <div class="col-sm-3">
                        <input required type="text" value="{$model.price}" name="price" class="form-control" value="面议" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">示意图：</label>
                    <div class="col-sm-3" >
                        <input type="file" accept="image/jpeg,image/jpg,image/png" name="thumb" class="form-control">
                    </div>
                    <div class="col-sm-6" id="pic_box">
                        <img class='thumb' width='100px' height='100px' src="{$model.thumb}" style='max-height:200px'  />
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-2">
                        <button class="btn btn-primary btn-sm"  type="submit">保存内容</button>
                        <div class="btn btn-white btn-sm" onclick="javascript:window.history.go(-1)">取消</div>
                    </div>
                </div>
            </form>

        </div>
    </div>
</div>
<script>
    $(function() {
        $("input[name='thumb']").on("change", function () {

            var objUrl = getObjectURL(this.files[0]); //获取图片的路径，该路径不是图片在本地的路径
            if (objUrl) {
                var tempStr = "<img class='thumb' width='100px' height='100px' style='max-height:200px'  />",
                    $label = $('#pic_box');
                $label.find('img.thumb').remove()
                $label.append(tempStr);
                $label.find('img.thumb').attr('src', objUrl);

            }
        });

    });

    function getObjectURL(file) {
        var url = null ;
        if (window.createObjectURL!=undefined) { // basic
            url = window.createObjectURL(file) ;
        } else if (window.URL!=undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file) ;
        } else if (window.webkitURL!=undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file) ;
        }
        return url ;
    }
</script>
